<?php
require_once("../Model/db_Dishes.cls.php");
require_once("../Model/db_Catedishes.cls.php");
require_once("../Model/db_Menu.cls.php");
class Dishes
{
	private $clsDishes;
	private $clsCategory;
	private $clsMenu;
	public function __construct()
	{
		$this->clsDishes = new db_Dishes();
		$this->clsCategory = new db_Catedishes();
		$this->clsMenu = new db_Menu();
	}
	
	public function selectDishes($id)
	{
		if(empty($id))
			return;
		$result = $this->clsDishes->select($id);
		return $result;
	}
	
	public function selectAll($id = '')
	{
		if(empty($id))
			return false;
 		return $this->clsDishes->selectAll($id);
	}
	
	
	public function getImage($id)
	{
		return $this->clsCategory->select($id);
	}
	public function getAllImage($id)
	{
		return $this->clsCategory->selectAll();
	}
	
	public function getMenu($IdMenu)
	{}
	public function getAllMenu($ResID)
	{
		return $this->clsMenu->selectAllMenu($ResID);
	}
	public function getAllDishes($id = '')
	{
		$menu = $this->getAllMenu($id);
		$allMenu = array();
		foreach($menu as $key => $value)
		{
			$dataMenu = $this->clsDishes->fetchDishesbyMenu($menu[$key]['MenuID'],$id);
			foreach( $dataMenu as $key => $value )
			{
				$image = $this->getImage($dataMenu[$key]['DishesID']);
				$rootPath = $image['rootPath'].$image['DishesName'].$image['Type'];// Tao duong dan den file picture
				if(file_exists($rootPath)){
					$imageString = file_get_contents($rootPath);//Doc file thanh String
					$imgEncode = base64_encode($imageString); // Encode ve base64
					$dataMenu[$key]['Image'] = $imgEncode; // Dua vao mang
				}
				else
					$dataMenu[$key]['Image'] = "None"; // Dua vao mang
			}
			$allMenu[] = $dataMenu;  //$dataMenu[$key]['MenuID']
		}
		$result = array('Status'=>'Success', 'Menu'=>$menu, 'Object'=> $allMenu);
		return $result;
	}
	public function getAllDishesMenu($id)
	{
		return $result;
	}
}
?>